package com.cg.servlet;

import com.cg.pojo.User;
import com.cg.service.UserService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.List;

@WebServlet("/user/list")
public class ListUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //通过UserService获取用户列表
        UserService service=new UserService();
        List<User> list =service.getList();

        //将用户列表储存到当前请求域
        req.setAttribute("users",list);
        //通过请求转发跳转到学生列表页面
        req.getRequestDispatcher("/userList.jsp").forward(req,resp);
    }
}
